package com.gsn.poker.packet;

import org.json.JSONException;
import org.json.JSONObject;

import com.badlogic.gdx.Gdx;
import com.gsn.common.CheckTimeout;
import com.gsn.dataCommon.ConfigModel;
import com.gsn.dataCommon.MakeRoomModel;
import com.gsn.dataCommon.MobileData;
import com.gsn.dataCommon.UserData;
import com.gsn.poker.game.MyPoker;

public class PacketFactory {
	public static final int TO = 0;
	public static final int TO_TAT_CA = 1;
	public static final int TO_1_2 = 2;
	public static final int TO_1_4 = 3;
	public static final int TO_GAP_DOI = 4;
	public static final int THEO = 5;

	private static JSONObject create() {
		JSONObject json = new JSONObject();
		try {
			json.put("ext", "Pokerhk");
		} catch (JSONException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

		return json;
	}

	public static JSONObject createLogin() {
		JSONObject json = null;
		try {
			String s = "{\"ext\":\"Pokerhk\",\"_cmd\":\"14\",\"params\":{}}";
			json = new JSONObject(s);
		} catch (JSONException e) {
			e.printStackTrace();
		}
		return json;
	}

	public static JSONObject createSelectChannel(int channelID) {
		JSONObject json = null;
		try {
			String s = "{\"ext\":\"Pokerhk\",\"_cmd\":\"200\",\"params\":{\"channelId\":" + channelID + "}}";
			json = new JSONObject(s);
		} catch (JSONException e) {
			e.printStackTrace();
		}
		return json;
	}

	public static JSONObject createCheatMoney(long nMoney, long nCoin) {
		JSONObject json = null;
		try {
			String s = "{\"ext\":\"Pokerhk\",\"_cmd\":131,\"params\":{\"nMoney\":" + nMoney + ", \"nCoin\":" + nCoin + "}}";
			// System.out.println(s);
			json = new JSONObject(s);
		} catch (JSONException e) {
			e.printStackTrace();
		}
		return json;
	}

	public static JSONObject createTO(int type) {
		JSONObject json = null;
		try {
			String s = "{\"ext\":\"Pokerhk\",\"_cmd\":\"104\",\"params\":{\"betType\":" + type + "}}";
			json = new JSONObject(s);
		} catch (JSONException e) {
			e.printStackTrace();
		}
		return json;
	}

	public static JSONObject createQuickPlay() {
		JSONObject json = null;
		try {
			String s = "{\"ext\":\"Pokerhk\",\"_cmd\":\"206\",\"params\":{}}";
			json = new JSONObject(s);
		} catch (JSONException e) {
			e.printStackTrace();
		}
		return json;
	}

	public static JSONObject createReady() {
		JSONObject json = null;
		try {
			String s = "{\"_cmd\":\"5\",\"ext\":\"Pokerhk\",\"params\":{}}";
			json = new JSONObject(s);
		} catch (JSONException e) {
			e.printStackTrace();
		}
		return json;
	}

	public static JSONObject createFold() {
		JSONObject json = null;
		try {
			String s = "{\"ext\":\"Pokerhk\",\"params\":{},\"_cmd\":\"106\"}";
			json = new JSONObject(s);
		} catch (JSONException e) {
			e.printStackTrace();
		}
		return json;
	}

	public static JSONObject createTheo(int bet) {
		JSONObject json = null;
		try {
			String s = "{\"ext\":\"Pokerhk\",\"params\":{\"betType\":0,\"chipBet\":" + bet + "},\"_cmd\":\"104\"}";
			json = new JSONObject(s);
		} catch (JSONException e) {
			e.printStackTrace();
		}
		return json;
	}

	public static JSONObject createQuitRoom() {
		JSONObject json = null;
		try {
			String s = "{\"ext\":\"Pokerhk\",\"_cmd\":\"4\",\"params\":{}}";
			json = new JSONObject(s);
		} catch (JSONException e) {
			e.printStackTrace();
		}
		return json;
	}

	public static JSONObject createShowFirstCard(int i) {
		JSONObject json = null;
		try {
			String s = "{\"ext\":\"Pokerhk\",\"_cmd\":\"101\",\"params\":{\"cardPos\":" + i + "}}";
			json = new JSONObject(s);
		} catch (JSONException e) {
			e.printStackTrace();
		}
		return json;
	}

	public static JSONObject createChat(String input) {
		JSONObject json = null;
		try {
			String s = "{\"ext\":\"Pokerhk\",\"params\":{\"message\":\"" + input + "\"},\"_cmd\":\"54\"}";
			json = new JSONObject(s);
		} catch (JSONException e) {
			e.printStackTrace();
		}
		return json;
	}

	public static JSONObject createNhuongTo(int id) {
		JSONObject json = null;
		try {
			String s = "{\"ext\":\"Pokerhk\",\"_cmd\":\"109\",\"params\":{\"PlayerID\":" + id + "}}";
			json = new JSONObject(s);
		} catch (JSONException e) {
			e.printStackTrace();
		}
		return json;
	}

	public static JSONObject createRequestStart() {
		JSONObject json = null;
		try {
			String s = "{\"ext\":\"Pokerhk\",\"params\":{},\"_cmd\":\"5\"}";
			json = new JSONObject(s);
		} catch (JSONException e) {
			e.printStackTrace();
		}
		return json;
	}

	public static JSONObject createExitChannel() {
		JSONObject json = null;
		try {

			String s = "{\"ext\":\"Pokerhk\",\"_cmd\":\"201\",\"params\":{}}";
			json = new JSONObject(s);
		} catch (JSONException e) {
			e.printStackTrace();
		}
		return json;
	}

	public static JSONObject createSelectRoom(int id, String pass) {
		JSONObject json = null;
		try {
			String s = "{\"ext\":\"Pokerhk\",\"_cmd\":\"207\",\"params\":{\"password\":\"" + pass + "\",\"tableId\":" + id + "}}";
			json = new JSONObject(s);
		} catch (JSONException e) {
			e.printStackTrace();
		}
		return json;
	}

	public static JSONObject chooseLeaf(int id) {
		// TODO Auto-generated method stub
		JSONObject json = new JSONObject();

		try {

			json = create().put("_cmd", CmdDefine.CMD_CHANGE_LEAF);
			JSONObject params = new JSONObject();
			params.put("leafId", id);
			json.put("params", params);

			// JSONObject params = new JSONObject().put("username",
			// pData().sessionKey);
			// json.put(CmdDefine.PARAMS, params);

		} catch (JSONException e) {
			e.printStackTrace();

		}
		return json;
		// sendNotification(NotificationNames.CHOSEN_LEAF);
	}

	public static JSONObject createViewRequest() {
		JSONObject json = null;
		try {
			String s = "{\"ext\":\"Pokerhk\",\"params\":{},\"_cmd\":\"113\"}";
			json = new JSONObject(s);
		} catch (JSONException e) {
			e.printStackTrace();
		}
		return json;
	}

	public static JSONObject createTakeChair(int chair) {
		JSONObject json = null;
		try {
			String s = "{\"ext\":\"Pokerhk\",\"_cmd\":\"208\",\"params\":{\"chair\":" + chair + "}}";
			json = new JSONObject(s);
		} catch (JSONException e) {
			e.printStackTrace();
		}
		return json;
	}

	public static JSONObject createCreateRoom() {
		JSONObject json = null;
		try {
			String s = "{\"_cmd\":\"204\",\"ext\":\"Pokerhk\",\"params\":{\"minGold\":0,\"bet\":15,\"tableName\":\"Đấu với cao thủ\",\"password\":\"\",\"type\":1}}";
			System.out.println(s);
			json = new JSONObject(s);
		} catch (JSONException e) {
			e.printStackTrace();
		}
		return json;
	}

	public static JSONObject createBaseInfoRequest() {
		JSONObject json = null;
		try {
			String s = "{\"_cmd\":\"10\",\"ext\":\"Pokerhk\",\"params\":{}}";
			json = new JSONObject(s);
		} catch (JSONException e) {
			e.printStackTrace();
		}
		return json;
	}

	public static void main(String[] args) {
		System.out.println("cheat : " + createCheatMoney(100, 200));
	}

	public static JSONObject loadConfig() {
		// sendNotification(NotificationNames.DOWNLOADED_CONFIG);

		JSONObject json = new JSONObject();
		try {

			json = create().put("_cmd", CmdDefine.LOAD_CONFIG);

			// JSONObject params = new JSONObject().put("username",
			// pData().sessionKey);
			// json.put(CmdDefine.PARAMS, params);

		} catch (JSONException e) {
			e.printStackTrace();

		}
		return json;

	}

	public static JSONObject mobile() {
		JSONObject json = new JSONObject();
		try {
			json = create().put("_cmd", 600);
			JSONObject params = new JSONObject();
			params.put("name", MobileData.name);
			params.put("device", MobileData.device);
			params.put("system", MobileData.osVersion);
			params.put("place", "");
			json.put("params", params);

		} catch (JSONException e) {
			e.printStackTrace();

		}
		return json;
	}

	public static JSONObject chooseRoom(int index) {

		// TODO Auto-generated method stub
		JSONObject json = new JSONObject();
		try {

			json = create().put("_cmd", CmdDefine.CMD_JOIN_ROOM);
			JSONObject params = new JSONObject().put("tableId", ConfigModel.tableModelList.get(index).id);
			params.put("tableIndex", ConfigModel.tableModelList.get(index).index);
			params.put("password", "");
			json.put("params", params);

			// JSONObject params = new JSONObject().put("username",
			// pData().sessionKey);
			// json.put(CmdDefine.PARAMS, params);

		} catch (JSONException e) {
			e.printStackTrace();

		}
		return json;
	}

	public static JSONObject shopGold(int id) {

		JSONObject json = new JSONObject();
		try {

			json = create().put("_cmd", CmdDefine.SHOP_GOLD);
			JSONObject params = new JSONObject().put("pack", id);

			json.put("params", params);

		} catch (JSONException e) {
			e.printStackTrace();

		}
		return json;
		// sendNotification(NotificationNames.SHOP_GOLD_SUCCESS, json);
		// sendNotification(NotificationNames.UPDATE_INFO_USER, json);
	}

	public static JSONObject getRefreshListTable() {
		// TODO Auto-generated method stub

		JSONObject json = new JSONObject();
		try {

			json = create().put("_cmd", CmdDefine.REFESH_LIST_TABLE);
			MyPoker.client.send(json);
			// JSONObject params = new JSONObject().put("username",
			// pData().sessionKey);
			// json.put(CmdDefine.PARAMS, params);

		} catch (JSONException e) {
			e.printStackTrace();

		}
		return json;
	}

	public static JSONObject updateListTable() {
		// TODO Auto-generated method stub

		JSONObject json = new JSONObject();
		try {

			json = create().put("_cmd", CmdDefine.CMD_UPDATE_ROOM_LIST);
			MyPoker.client.send(json);
			// JSONObject params = new JSONObject().put("username",
			// pData().sessionKey);
			// json.put(CmdDefine.PARAMS, params);

		} catch (JSONException e) {
			e.printStackTrace();

		}
		return json;
	}

	public static JSONObject makeARoom() {

		JSONObject json = new JSONObject();
		try {

			json = create().put("_cmd", CmdDefine.CMD_CREATE_ROOM);
			JSONObject params = new JSONObject();
			params.put("type", MakeRoomModel.type);
			params.put("minGold", MakeRoomModel.minGold);
			params.put("bet", MakeRoomModel.bet);
			params.put("tableName", MakeRoomModel.name);
			params.put("password", MakeRoomModel.password);

			// params.put("type", 1);
			// params.put("minGold", 0);
			// params.put("bet", 15);
			// params.put("tableName", "fd");
			// params.put("password", "");

			json.put("params", params);

			// JSONObject params = new JSONObject().put("username",
			// pData().sessionKey);
			// json.put(CmdDefine.PARAMS, params);

		} catch (JSONException e) {
			e.printStackTrace();

		}
		return json;

	}

	public static JSONObject playNow() {

		// TODO Auto-generated method stub
		JSONObject json = new JSONObject();
		try {

			json = create().put("_cmd", CmdDefine.CMD_QUICK_PLAY);

			// JSONObject params = new JSONObject().put("username",
			// pData().sessionKey);
			// json.put(CmdDefine.PARAMS, params);

		} catch (JSONException e) {
			e.printStackTrace();

		}
		return json;
	}

	public static JSONObject getDailyGift() {
		// TODO Auto-generated method stub

		JSONObject json = new JSONObject();
		try {

			json = create().put("_cmd", CmdDefine.CMD_GET_DAILY_GIFT);
			JSONObject params = new JSONObject().put("index", UserData.giftIndex);
			UserData.giftIndex = 0;
			json.put("params", params);

		} catch (JSONException e) {
			e.printStackTrace();

		}
		return json;
	}

	public static JSONObject getSupportBean() {
		// TODO Auto-generated method stub

		JSONObject json = new JSONObject();
		try {
			json = create().put("_cmd", CmdDefine.CMD_SUPPORT_BEAN);

		} catch (JSONException e) {
			e.printStackTrace();

		}
		return json;
	}

	public static JSONObject sendEmo(int body) {
		// TODO Auto-generated method stub

		JSONObject json = new JSONObject();
		try {

			json = create().put("_cmd", CmdDefine.CMD_EMOTICON);
			JSONObject params = new JSONObject();
			params.put("emoIndex", body);
			json.put("params", params);

		} catch (JSONException e) {
			e.printStackTrace();

		}
		return json;
	}

	public static JSONObject cheatJackpot(long body) {
		// TODO Auto-generated method stub

		JSONObject json = new JSONObject();
		try {

			json = create().put("_cmd", 132);
			JSONObject params = new JSONObject();
			params.put("nJackpot", body);
			json.put("params", params);

		} catch (JSONException e) {
			e.printStackTrace();

		}
		return json;
	}

	public static JSONObject createEcho() {
		// TODO Auto-generated method stub
		CheckTimeout.getInstance().update();
		JSONObject json = new JSONObject();
		try {

			json = create().put("_cmd", 1000);

		} catch (JSONException e) {
			e.printStackTrace();

		}
		return json;
	}

}
